/**
 * Created by dbwyxl on 2017/9/11.
 */
module.exports =function(httpservice,$http,$q){

  var orderReceivingService = {
    getOrderTotal:getOrderTotal,
    getConsultOrderPageList:getConsultOrderPageList,
    getServiceType:getServiceType,
    getBusinessType:getBusinessType,
    findConsultOrderInfo:findConsultOrderInfo,
    addConsultOrderMsg:addConsultOrderMsg,
    sumbitAccept:sumbitAccept,
    fileDownload:fileDownload,
    sFileDownload:sFileDownload
  };
  /*统计数字*/
  function getOrderTotal () {
    return $http({
      method: 'POST',
      url: httpservice.findConsultOrderStatisticsUrl,
      data:{}
    });
  }

  //获取左侧列表
  function getServiceType() {
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.getServiceTypeUrl,
      params: '',
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }

  //筛选列表
  function getBusinessType(){
    return $http({
      method: 'POST',
      url: httpservice.getBusinessTypeUrl,
      data:{}
    })
  }

  /*接单中心分页查询列表*/
  function getConsultOrderPageList (params) {
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.findConsultOrderPageListUrl,
      data:params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }

  //接单中心 详情页
  function findConsultOrderInfo(params){
    return $http({
      method: 'POST',
      url: httpservice.findConsultOrderInfoUrl,
      data:params
    })
  }

  //接单中心 回复消息
  function addConsultOrderMsg(params){
    return $http({
      method: 'POST',
      url: httpservice.addConsultOrderMsgUrl,
      data:params
    })
  }

  //接单中心 提交验收
  function sumbitAccept(params){
    return $http({
      method: 'POST',
      url: httpservice.sumbitAcceptUrl,
      data:params
    })
  }

  //下载附件
  function fileDownload (params) {
    return $http({
      method:"POST",
      url:httpservice.consultFileDownloadUrl,
      params:params,
      responseType: 'arraybuffer',
      headers:{'Content-Type':'application/json'},
    })
  };

  //案源下载附件
  function sFileDownload (params) {
    return $http({
      method:"POST",
      url:httpservice.servicecaseFileDownloadUrl,
      params:params,
      responseType: 'arraybuffer',
      headers:{'Content-Type':'application/json'},
    })
  };

  return orderReceivingService;
};
